<div id="subGraph" 
    style="
        display: none;
        border: 1px solid #aaa;
        display: table;
        margin-left: auto;
        margin-right: auto;
    ">
    <?php
        foreach ($mainCost as $keyCost => $valueCost) {
            $subCost=$costObj->getSubCost($valueCost["costID"]);
            foreach ($cropID as $keyCrop => $value) {
                $cropClass=new crop($value);
                $crop=$cropClass->getCrop();
                $farmID=$crop["farmID"];
                $farmClass=new farm($farmID);
                $farm=$farmClass->getFarm();
                $memID=$farm["memID"];
                $memberClass=new member($memID);
                $member[$keyCrop]=$memberClass->getMember();

                foreach ($subCost as $keyCost => $valueM) {
                    $val[$keyCrop][$keyCost]=$cropClass->percentSubCost($valueCost["costID"],$keyCost);
                }
            }
            ?>
    <div id="subGraph<?=$valueCost["costID"]?>" class="subGraphAll" style="text-align: center;padding: 20px;display: none;">
        <span style="font-size: 80%;">
            แผนภูมิแท่งเปรียบเทียบต้นทุน
            <?php
                $costTempObj = new cost($valueCost["costID"]);
                $costName=$costTempObj->getCost();
                echo $costName["costName"];
            ?>
        </span>
        <table class="noSpacing" style="margin-left: auto;margin-right: auto;margin-top: 30px;">
            <tr>
                <td style="vertical-align: top;border-right: 1px solid #000;">
                    <div style="position: relative;height: 100%;">
                        <div style="position: absolute;top: -25px;left:-18px;font-size: 60%;white-space: pre;">บาท/ไร่</div>
                    </div>
                </td>
                <?php
                    foreach ($val as $key => $value) {
                        $max[]=max($value);
                    }
                    $maxVal=max($max);
                    $maxHeight=250;
                    foreach ($subCost as $keyCost => $valueCost) {
                        ?>
                <td style="vertical-align: bottom;text-align: center;font-size: 80%;padding: 5px 10px 5px 10px;cursor: pointer;">
                    <div style="position: relative">
                        <table class="noSpacing">
                            <tr>
                                <?php
                            $i=0;
                            foreach ($cropID as $keyCrop => $valueCrop) {
                                if($maxVal==0){
                                    $height=0;
                                }else{
                                    $height=((100*$val[$keyCrop][$keyCost])/$maxVal)*($maxHeight/100);
                                }
                                $height=$val[$keyCrop][$keyCost]*2;
                                ?>
                                <td style="vertical-align: bottom;font-size: 60%;">
                                    <?=  number_format($val[$keyCrop][$keyCost])?>%
                                    <div 
                                        style="
                                            background-color: <?=$color[$i]?>;
                                            width: 25px;
                                            height: <?=$height?>px;
                                        "></div>
                                </td>
                                    <?php
                                $i++;
                            }
                            ?>
                            </tr>
                        </table>
                        <div style="
                            position: absolute;
                            display: none;
                            width: 100%;
                            height: <?=$valueCost["stdPercent"]*6?>px;
                            bottom: 0px;
                            border-top: 1px dashed #aaa;
                        "></div>
                    </div>
                </td>
                            <?php
                    }
                ?>
            </tr>
            <tr>
                <td></td>
                <?php
                foreach ($subCost as $key => $value) {
                        ?>
                <td style="vertical-align: top;text-align: center;font-size: 60%;padding: 5px;border-top: 1px solid #000;">
                    <div style="max-width: 70px;margin-left: auto;margin-right: auto;">
                        <?php
                            $costObj = new cost($key);
                            $costName=$costObj->getCost();
                            echo $costName["costName"];
                        ?>
                    </div>
                </td>
                            <?php
                    }
                ?>
            </tr>
        </table>
    </div>
                <?php
        }
    ?>
</div>